import store from "@/store";
import { nextTick } from "vue";
import { UPDATE_VIEWTAGS } from "@/store/types";

export function beforeEach(to, from) {
  var adminMain = document.querySelector("#adminui-main");
  if (!adminMain) {
    return false;
  }
  store.commit(`viewTags/${UPDATE_VIEWTAGS}`, {
    fullPath: from.fullPath,
    scrollTop: adminMain.scrollTop,
  });
}

export function afterEach(to) {
  var adminMain = document.querySelector("#adminui-main");
  if (!adminMain) {
    return false;
  }
  nextTick(() => {
    var beforeRoute = store.state.viewTags.viewTags.filter(
      (v) => v.fullPath == to.fullPath
    )[0];
    if (beforeRoute) {
      adminMain.scrollTop = beforeRoute.scrollTop || 0;
    }
  });
}
